package com.hdoit.ares.logical.team.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.hdoit.ares.logical.team.dao.ICooperationTeamDao;
import com.hdoit.ares.logical.team.model.CooperationTeam;
import com.hdoit.ares.logical.viewmodel.team.CooperationTeamSearch;
import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.enums.OrderEnum;
import com.tennetcn.common.logical.superbase.model.Employee;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.utils.FinderExpressionFactory;
/**
 * @author      yujinhui
 * @email       
 * @createtime  2018年01月18日 14:26:32
 * @comment
 */
@Component
public class CooperationTeamDaoImpl extends SuperDao<CooperationTeam> implements ICooperationTeamDao{

	@Override
	public List<CooperationTeam> queryList(CooperationTeamSearch cooperationTeamSearch,
			PagerModel pagerModel, String employeeAccount) {

		IFinderExpression businessIdFinder = FinderExpressionFactory.createExpression();
		businessIdFinder.select("businessId")
						.from(Employee.class)
						.andWhere("employeeAccount=#{employeeAccount}");
		
		IFinderExpression childFinder = FinderExpressionFactory.createExpression();
		childFinder.select("employeeId")
						.from(Employee.class)
						.andWhere("businessId = ("+businessIdFinder.toSql()+")");
		
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("*")
						.from(CooperationTeam.class)
						.andWhere("employeeId in ("+childFinder.toSql()+")")
						.setParam("employeeAccount", employeeAccount)
						.addOrder("createDate", OrderEnum.desc);
		return queryList(finderExpression, cooperationTeamSearch, pagerModel);
	}

}